package com.java.star.novel.controller;


import com.java.star.novel.core.bean.Result;
import com.java.star.novel.no.to.CommentAddTO;
import com.java.star.novel.no.to.ReplyAddTO;
import com.java.star.novel.service.CommentReplyService;
import com.java.star.novel.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.java.star.novel.core.enums.ResultCode.ERROR;

@RestController
@RequestMapping("comment")
@Api(description = "评论接口")
public class CommentController {

    @Autowired
    private CommentService commentService;
    @Autowired
    private CommentReplyService commentReplyService;

    @ApiOperation("添加小说评论")
    @PostMapping("addComment/{novelId}")
    public Result addComment(@PathVariable Long novelId, @RequestBody CommentAddTO commentAddTO) {
        try {
            return commentService.addComment(novelId, commentAddTO);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result().code(ERROR);//报500, "服务器异常"
        }
    }

    @ApiOperation("添加评论回复")
    @PostMapping("addCommentReply/{novelId}/{commentId}")
    public Result addCommentReply(@PathVariable Long novelId, @PathVariable Long commentId,
                                  @RequestBody ReplyAddTO replyAddTO) {
        try {
            return commentReplyService.addCommentReply(novelId, commentId, replyAddTO);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result().code(ERROR);//报500, "服务器异常"
        }
    }

}
